package com.neuedu.collection.List;

import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;

public class LinkedListDemo {
    public static void main(String[] args) {
        LinkedList  list = new LinkedList();
        list.add("张三");
        list.add("李四");
        list.add("王五");
        LinkedList  list2 = new LinkedList();
        list2.add(1);
        list2.add(2);
        list2.add(3);
        list2.addAll(2,list);
        System.out.println(list2);
        list2.addFirst("first");
        list2.addLast("last");
        System.out.println(list2);

        System.out.println(list2.getFirst());
        System.out.println(list2.getLast());

        System.out.println(list2.element());
        System.out.println(list2);
        System.out.println(list2.offer("张三"));///add
        System.out.println(list2);
        System.out.println( list2.peek());  //get  getfirst
        System.out.println(list2);
        System.out.println(list2.poll());//弹出
        System.out.println(list2);
        System.out.println(list2.pop());////弹出
        System.out.println(list2);

        ///测试sort
        LinkedList<Integer>   list3 = new LinkedList();
        list3.add(2);
        list3.add(12);
        list3.add(4);
        list3.add(1);
        list3.add(9);
        System.out.println(list3);
        list3.sort(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1-o2;
            }
        });
        System.out.println(list3);
         List  list4 = list3.subList(1,4);// 截取一段  包含起始位置  不含终止位置
        System.out.println(list4);
        list3.forEach(System.out::println);//// Java8 lamda
        System.out.println("=============");
        list3.forEach(x-> System.out.println(x));////Java8 lamda

    }
}
